﻿$(function () {
    loadmenu();
})

function loadmenu() {
    $.ajax({
        type: "get",
        url: "/home/getmenu",
        async: false,
        success: function (menus) {
            var tmphtml = initmenu(menus);
            $('#leftmenu').html(tmphtml);
        }
    })
}

function initmenu(menus) {
    var tmphtml = '';
    for (var i = 0; i < menus.length; i++) {
        if (i == 0) {
            tmphtml += '<li class="layui-nav-item  layui-nav-itemed">';
        }
        else {
            tmphtml += '<li class="layui-nav-item">';
        }
        tmphtml += '<a class="" href="javascript:;">' + menus[i].Title + '</a>';
        var m = menus[i].Childrens.length;
        if (m > 0) {
            tmphtml += '<dl class="layui-nav-child">';
            for (var j = 0; j < m; j++) {
                tmphtml += '<dd><a class="site-active" tab-name="' + menus[i].Childrens[j].Title + '" tab-url="' + menus[i].Childrens[j].Url + '" tab-layid="' + menus[i].Childrens[j].Id + '">' + menus[i].Childrens[j].Title + '</a></dd>'
            }
            tmphtml += '</dl>';
        }
        tmphtml += '</li>';
    }
    return tmphtml;
}